<?php

declare(strict_types=1);

/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use function Hyperf\Support\env;
use function Hyperf\Support\value;

return [
    'default' => [
        'handler' => [
            'class' => Monolog\Handler\RotatingFileHandler::class,
            'constructor' => [
                'filename' => BASE_PATH . '/runtime/logs/hyperf.log',
                'level' => env('APP_ENV', 'prod') == 'prod' ? Monolog\Logger::INFO : Monolog\Logger::DEBUG,
            ],
        ],
        'formatter' => [
            'class' => value(function () {
                return env('APP_ENV', 'prod') == 'prod' ? Monolog\Formatter\JsonFormatter::class : Monolog\Formatter\LineFormatter::class;
            }),
            'constructor' => value(function () {
                return env('APP_ENV', 'prod') == 'prod' ?
                    [] :
                    [
                        'format' => "[%level_name%] %datetime% =>> %channel% =>> %message% =>> %context% =>> %extra%\n",
                        'dateFormat' => 'Y-m-d H:i:s',
                        'allowInlineLineBreaks' => true,
                        'includeStacktraces' => true,
                    ];
            }),
        ],
        'processors' => [
            [
                'class' => Common\Kernel\Log\AppendRequestIdProcessor::class,
            ],
            [
                'class' => Monolog\Processor\HostnameProcessor::class,
            ],
            [
                'class' => Monolog\Processor\UidProcessor::class,
            ],
            [
                'class' => Monolog\Processor\MemoryUsageProcessor::class,
            ],
            [
                'class' => Monolog\Processor\MemoryPeakUsageProcessor::class,
            ],
            [
                'class' => Monolog\Processor\ProcessIdProcessor::class,
            ],
            [
                'class' => Monolog\Processor\WebProcessor::class,
            ],
            [
                'class' => Monolog\Processor\PsrLogMessageProcessor::class,
            ],
            [
                'class' => Monolog\Processor\IntrospectionProcessor::class,
            ],
        ],
    ],
];
